import { HOST_URL } from "../../config/index"

const { marked } = require('./../../utils/marked.umd')


Component({
  data: {
    top: 0,
    moonObj: null as any,
    article: '',
  },
  lifetimes: {
    attached() {
      const { statusBarHeight } = wx.getWindowInfo()
      this.setData({
        top: statusBarHeight,
      })
      const moonObj = wx.getStorageSync('moonObj')
      if (moonObj) {
        moonObj.extraMeaning = JSON.parse(moonObj.extraMeaning)
        this.setData({
          moonObj,
        })
      }
    },
  },
  methods: {
    goback() {
      wx.navigateBack()
    },
    aijiedu() {
      if (this.data.article) return
      wx.showLoading({
        title: 'ai正在思考中',
        mask: true,
      })
      wx.request({
        url: HOST_URL + 'moon/ai',
        method: 'GET',
        data: {
          id: this.data.moonObj.id,
        },
        success: (res: any) => {
          wx.hideLoading()
          
          const markdownText = marked.parse(res.data.data.huida);
          console.log(markdownText)
  
          this.setData({
            article: markdownText,
          })
        },
      })
    }
  },
})
